package com.jf.cloud.service.sysmanager.support.web;

import com.jf.cloud.service.sysmanager.common.util.Crypter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;


@Controller
public class CrypterController  extends BaseController{

	/**
	 * ½âÃÜ
	 */
	@RequestMapping("/decode")
	public ModelAndView wordFilter(String content, HttpServletRequest request){
		ModelAndView mv = new ModelAndView();

        String pwd = this.getParamValueString(request, "pwd");
        pwd = getRealPwd(pwd);
        mv.addObject("pwd", pwd);
        mv.setViewName("../0808");
		return mv;
	}
	
    public static String getRealPwd(String pwdStr){
    	String pre_str = pwdStr;
    	String new_str = pwdStr;
    	char[] result_str = pwdStr.toCharArray();
    	
    	
    	do{
    		if(new_str == null || new_str.length()==0){
    			return pre_str;
        	}
    		result_str = Crypter.decrypt(new_str).toCharArray();
        	new_str = Crypter.decrypt(new_str);
    		for(int i = 0 ;i<result_str.length; i++){
        		if((int)result_str[i]>256){
        			return pre_str;
        		}
    			//System.out.print("["+(int)result_str[i]+"]");
    		 }
    		if(!"".equals(new_str)){
    			pre_str = new_str;
    		}
    		
    	}while(true);
    	
    }	
}
